package client

import (
	"github.com/micro/go-micro"
	"lab-service/config"
	pm "lab-service/proto/message"
	pn "lab-service/proto/notice"
	pp "lab-service/proto/post"
	ps "lab-service/proto/security"
	pu "lab-service/proto/user"
)

var (
	securityService ps.SecurityService
	userClient      pu.UserService
	postClient      pp.PostService
	messageClient   pm.MessageService
	noticeClient    pn.NoticeService
)

func SecurityClient() ps.SecurityService {
	if securityService == nil {
		securityService = ps.SecurityServiceClient(
			config.GetConfig().SecurityService.Name,
			micro.NewService().Client())
	}
	return securityService
}

func PostClient() pp.PostService {
	if postClient == nil {
		postClient = pp.PostServiceClient(
			config.GetConfig().PostService.Name,
			micro.NewService().Client())
	}
	return postClient
}

func MessageClient() pm.MessageService {
	if messageClient == nil {
		messageClient = pm.MessageServiceClient(
			config.GetConfig().PostService.Name,
			micro.NewService().Client())
	}
	return messageClient
}

func NoticeClient() pn.NoticeService {
	if noticeClient == nil {
		noticeClient = pn.NoticeServiceClient(
			config.GetConfig().PostService.Name,
			micro.NewService().Client())
	}
	return noticeClient
}

func UserClient() pu.UserService {
	if userClient == nil {
		userClient = pu.UserServiceClient(
			config.GetConfig().AccountService.Name,
			micro.NewService().Client())
	}
	return userClient
}
